<?php
namespace App\Models;
use Illuminate\Support\Facades\DB;

class Log extends CommonModel {

    /**
     * 增加访客记录，商品查看记录，
     * @param $goods_id int 商品ID
     * @param $goods_type int 商品类型
     * @param $uid int 用户ID
     * @param $store_id int 店铺ID
     */
    public function addGoodsView($goods_id, $goods_type,$uid,$store_id){
        LogGoodsView::addGoodsView($goods_id, $goods_type,$uid,$store_id);
        LogStoreView::addStoreView($uid,$store_id);
    }

    /**
     * 下单增加库存销量以及访客记录
     * @param $goods_id
     * @param $goods_type
     * @param $uid
     * @param $store_id
     * @param $goods_num
     */
    public function addGoodsStock($goods_id,$goods_type,$uid,$goods_num){
        if($goods_type==1){
            $update = ShopSeckillGoods::updatedGoodsStock($goods_id);
            $store_id = ShopSeckillGoods::where(['id'=>$goods_id])->value('store_id');
        }else if($goods_type==2){
            $update = ShopGroupGoods::updatedGoodsStock($goods_id,$goods_num);
            $store_id = ShopGroupGoods::where(['id'=>$goods_id])->value('store_id');
        }else{
            $update = ShopGoods::updatedGoodsStock($goods_id,$goods_num);
            $store_id = ShopGoods::where(['id'=>$goods_id])->value('store_id');
        }

        self::addGoodsView($goods_id,$goods_type,$uid,$store_id);
        return $update;
    }
}